﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NLUNZ.Business;

namespace NLUNZ.Register
{
    public partial class ResetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text.Trim();
            if(!string.IsNullOrEmpty(username))
            {
                //check username find email
                if(Repository.IsUserActive(username))
                {
                    
                    string email = Repository.GetUserEmailByUsername(username);
                    string password = Repository.GetUserPasswordByUsername(username);
                    string body =
                        string.Format(
                            "<h2>Password Recovery</h2><div style='margin:40px;'>Hi {0}, You have recently request your password. Your password is <span><b>{1}</b></span>.</div>",
                            username, password);
                    Repository.SendEmail("Email Recovery", body);
                    message.Text =
                        Utility.SuccessHtml(String.Format("Your password has been send to your email {0}. You can <a href='../Admin'>login</a> after you receive your passowrd.", email));
                }
                else
                {
                    message.Text = Utility.ErrorHtml("This username is either not active or has been deleted, please contact administration.");
                }
            }
            else
            {
                message.Text = Utility.ErrorHtml("Username field is emtpy.");
            }
        }
    }
}